<?php namespace Common\Model;

use Hdphp\Model\Model;

class Goodslist extends Model{
	protected $table = "goodslist";


	//自动验证
	 protected $validate = array( 
	    array('glvalue','required','组合属性不能为空',3,3),
	    array('glnum','required','货号不能为空',3,3),
	    array('gltotal','required','库存不能为空',3,3),
	    
	);
	
	
	
	
	public function store(){
	    if(!$this->create()) return false;
		//接受数据
		$formData=Q('post.');
		//处理数据
		$this->data['glvalue']=implode(',', $this->data['glvalue']);
		//添加数据
		$formData['glid']=$this->add();
		//查找数据商品属性表
		$this->gamodel=new \Common\Model\shopnature;
		foreach ($formData['glvalue'] as $k =>$v) {
			$formData['glvalue'][$k]=$this->gamodel->where('sid='.$v)->pluck('shopvalue');
		}
		return $formData;
	}
	
	
	
	
	//编辑验证
	public function edit(){
//		判断验证
	    if(!$this->create()) return false;
		$this->data['glvalue']=implode(',', $this->data['glvalue']);
		$this->save();
		return true;
	}
}